<?php 
include("common/conn.php");  
include("tool/UpFileTool.class.php");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>e网批发管理后台</title>
    <?php 
    if($_SESSION['userid']==""){echo "<script>window.location.href='login.php';</script>";} 
    
    if($_GET['action']=="ok"){   
        if($_FILES['pics']['name']!=''){
            $UpFileTool=new UpFileTool('pics');
            $images=$UpFileTool->upFile();
        }
        $image = isset($images) ? $images :''; 
        $srat=mysql_query("INSERT INTO zifenlei(name,fenleiid,type,pic) VALUES ('$_POST[name]','$_GET[id]','$_REQUEST[type]','".$image."')");
    }

    if($_GET['del']=="ok"){
        $srat1=mysql_query("DELETE FROM zifenlei  where id='".$_REQUEST['iid']."'");
    }


   /* if($_GET['del']=="ok")
    {

        $srat1=mysql_query("DELETE FROM goods where goodsid='".$v."'");
    }*/

    if($_GET['gai']=="ok"){
        $vs = array(); 
        $vs= $_POST['names'];
        
        $ss= array(); 
        $ss= $_POST['fid'];

        $type = $_POST['type'];
        $longth=count($ss);
        //var_dump($_POST['checkbox']);die;
        foreach($ss as $k=>$v){
            if($_FILES[pics][name][$k]!=''){
                $tmpfile = $_FILES[pics][tmp_name][$k];
                $filefix = array_pop(explode(".", $_FILES['pics']['name'][$k]));
                $dstfile = "srcimage/files/".time()."_".mt_rand().".".$filefix;
                if(move_uploaded_file($tmpfile, $dstfile)){
                   $query = mysql_query("UPDATE zifenlei set pic='".$dstfile."' where id=".$v);
                }   
            }
            //var_dump($_POST);die;
        }
        if($_POST['checkbox']){
            foreach($_POST['checkbox'] as $v){
                $query = mysql_query("UPDATE zifenlei set isHot=1 where id=".$v);
            }          
        }

        for($d=0;$d<$longth;$d++){
            /*$rert37=mysql_query("select * from zifenlei  where  id='".$ss[$d]."'");
            $sdg37=mysql_fetch_array($rert37);
            $zifu=(string)$sdg37[name];
            $sratd = mysql_query("update goods set zixilie='".$vs[$d]."' where zixilie  like '".$zifu."%'");*/
            $srat1=mysql_query("update zifenlei set name='".$vs[$d]."',type='".$type[$d]."' where id='".$ss[$d]."'");
        }
        echo "<script>alert('修改成功');window.location.href='addzifen.php?id=".$_REQUEST[id]."</script>";
    }
    //var_dump($sdg37);die;
    ?>

    <script type="text/javascript" src="js/jquery.min.js"></script>
    <link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>

<body>

    <!--header-->
    <?php include("common/header.php");?>
    <!--header end-->
    <div id="sub_nav">

        <div id="subnav_wrap" class="container_12">
            <div id="subnav" class=" grid_12">

                <ul>
                    <li> <a href="fenlei.php" class="sub_nav_active"> 分类管理 </a></li>
                    <li><a href="fenlei_leixing.php">分类属性</a></li>
                </ul>

            </div>

        </div>


    </div>
    <div class="container_12">
        <form action="?action=ok&id=<?php echo $_GET['id'];?>" method="post" enctype="multipart/form-data">
            <h3 style="color:red;">添加子分类</h3>
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <tr>
                        <th width="15%" scope="col">子分类名称</th>
                        <th width="30%" scope="col">
                            <input name="name" type="text"  />
                        </th>

                        <th width="10%" scope="col">类型</th>
                        <th width="30%" scope="col">
                            <select name="type">
                                <option value="0">海淘</option>
                                <option value="1">快购</option>
                            </select>
                        </th>
                        <th width="15%" scope="col">图片</th>
                        <th width="30%" scope="col">
                            <input name="pics" type="file"  class="text"/>
                        </th>
                        <th width="10%" scope="col">
                           <input name="" type="submit" value="提交" />
                        </th>
                    </tr>
                </tr>
            </table>
        </form>
        <div  style="margin:30px;"></div>
        <!-- END TABULAR DATA EXAMPLE -->
        <form enctype="multipart/form-data" action="?gai=ok<?php if($_GET['pt']!=""){echo "&ch=ok";} ?>&id=<?php echo $_REQUEST[id];?>" method="post">
        <h3 style="color:red;">子分类列表</h3>   
            <table  width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr> 
                    <th width="8%" scope="col">选为热销</th>
                    <th width="20%" scope="col">分类名称</th>
                    <th scope="col">图片</th>
                    <th width="20%" scope="col">类型</th>
                    <th width="20%" scope="col">操作</th>
                </tr>
                <?php 
                $rert37 = mysql_query("select * from zifenlei  where  fenleiid='".$_REQUEST[id]."' order by id desc ");
                while($sdg37=mysql_fetch_array($rert37)){?>
                <tr>
                    <td><input type="checkbox" name="checkbox[]" <?php if($sdg37[isHot]==1){echo "checked";} ?> value="<?php echo $sdg37[id];?>" /></td>

                    <td width="20%" scope="col"><input name="names[]" type="text"  value="<?php echo $sdg37[name];?>"/><input name="fid[]" type="hidden"  value="<?php echo $sdg37[id];?>" /></td>

                    <td width="20%" scope="col">
                        <input width="30%" name="pics[]" type="file" class="text"/>
                  
                        <?php if ($sdg37[pic]!='') { ?>
                            <img src="<?php echo $sdg37[pic]; ?>" style="height:auto;width:200px;border-radius:3%;"/>
                        <?php } ?>
                    </td>

                    <td width="20%" scope="col">
                        <select name="type[]">
                            <option value="0" <?php if ($sdg37[type] ==0) { ?> selected <?php } ?>>海淘</option>
                            <option value="1" <?php if ($sdg37[type] ==1) { ?> selected <?php } ?>>快购</option>
                        </select>
                    </td>

                    <td width="20%" scope="col">
                            <a href="?id=<?php echo $_REQUEST[id];?>&iid=<?php echo $sdg37[id];?>&del=ok">删除</a>
                            <a href="addguige.php?ziid=<?php echo $sdg37[id]; ?>&id=<?php echo $_REQUEST[id]; ?>" style="color:#0000EE;">设置规格</a>
                    </td>
                </tr>
                <?php }?>

                <tr> <th colspan="6" scope="col"><input value="确定" type="submit" /></th>
                </tr>
            </table>

        </form>         
    </div>
</body>
</html>
